package com.ythook.mentor.repository;

import com.ythook.mentor.entity.MentorCalendar;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Repository
public interface MentorCalendarRepository extends JpaRepository<MentorCalendar,Long> {

    @Modifying
    @Query(value = "delete from MentorCalendar m where m.mentorId=?1")
    Integer deleteByMentorId(Long mentorId);

    @Query(value = "select m from MentorCalendar m where m.mentorId=?1")
    Optional<MentorCalendar> findAllByMentorId(Long mentorId);

    Optional<MentorCalendar> findByMentorId(Long mentorId);

    @Query(value = "select m from MentorCalendar m where m.startDate > ?1 and m.endDate < ?2")
    List<MentorCalendar> findAllByDate(Date startDate, Date endDate);
}
